home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / HTML Markup 3.0 ƒ / markup.pl < prev   
Encoding:
Text File  |  1999-07-25  |  3.0 KB  |  188 lines

  1. # markup.pl
  2. # ---------
  3. # Perl functions for HTML Markup 3.0
  4. # History
  5. # 1.0 by klep (klep@cs.stanford.edu) on 5/12/99
  6. # 1.1 by klep (klep@cs.stanford.edu) on 7/25/99
  7. #
  8. # You may NOT distribute modified versions of this file with the HTML
  9. # Markup distribution. Send them to <klephacks@kagi.com> or distribute
  10. # them separate from the rest of HTML Markup.
  11. #
  12. # Modify this file at your own risk. Do not change any function names
  13. # or parameters.
  14.  
  15.  
  16.  
  17.  
  18. # Conversion
  19.  
  20. sub ltgttobrackets {
  21.     my($input) = @_;
  22.     
  23.     $input =~ s/</</gs;
  24.     $input =~ s/>/>/gs;
  25.     
  26.     return $input;
  27. }
  28.  
  29.  
  30. # URL Recognition
  31.  
  32. sub convert_url {
  33.     my($input, $scheme) = @_;
  34.     my($output) = "";
  35.  
  36.     while ($input =~ m"(.*?)$scheme([A-Za-z0-9./]*)"is)
  37.     {
  38.         $output = $output . "$1<a href=\"$scheme$2\">$scheme$2</a>";
  39.         $input = $';  #'
  40.     }
  41.  
  42.     return $output . $input;
  43. }
  44.  
  45. sub http {
  46.     my($input) = @_;
  47.  
  48.     my($output) = convert_url($input, "http://");
  49.     return convert_url($output, "https://");
  50. }
  51.  
  52. sub ftp {
  53.     my($input) = @_;
  54.     
  55.     return convert_url($input, "ftp://");
  56. }
  57.  
  58. sub news {
  59.     my($input) = @_;
  60.     
  61.     return convert_url($input, "news:");
  62. }
  63.  
  64. sub mailto {
  65.     my($input) = @_;
  66.     
  67.     return convert_url($input, "mailto:");
  68. }
  69.  
  70. sub email {
  71.     my($input) = @_;
  72.     my($output) = "";
  73.     
  74.     while ($input =~ m"([A-Za-z0-9.]*?)\@([A-Za-z0-9.]*)"is)
  75.     {
  76.         $output = $output . $` . "<a href=\"mailto:$1\@$2\">$1\@$2</a>";   #`
  77.         $input = $';   #'
  78.     }
  79.     
  80.     return $output . $input;
  81. }
  82.  
  83.  
  84. # Source Document
  85.  
  86. sub makehtml {
  87.     my($input, $headparams, $bodyparams, $tophtml) = @_;
  88.     
  89.     return "<HTML>\r\t<HEAD>\r\t\t$headparams\r\t</HEAD>\r<BODY $bodyparams>\r$tophtml\r" . "$input" . "\r</BODY>\r</HTML>";
  90. }
  91.  
  92.  
  93. # Line Breaks
  94.  
  95. sub endlinesbr {
  96.     my($input) = @_;
  97.     
  98.     $input =~ s/\r/<BR>\r/gs;
  99.     $input =~ s/\n/<BR>\n/gs;
  100.     
  101.     return $input;
  102. }
  103.  
  104. sub endlinesp {
  105.     my($input) = @_;
  106.     
  107.     $input =~ s/\r/<P>\r/gs;
  108.     $input =~ s/\n/<P>\n/gs;
  109.     
  110.     return $input;
  111. }
  112.  
  113.  
  114. # Misc
  115.  
  116. sub linesdashed {
  117.     my($input, $length, $thickness) = @_;
  118.     
  119.     $input =~ s/\r\n(-){3,}\r\n/\r\n<HR width=$length size=$thickness>\r\n/gs;
  120.     $input =~ s/\r(-){3,}\r/\r<HR width=$length size=$thickness>\r/gs;
  121.     $input =~ s/\n(-){3,}\n/\n<HR width=$length size=$thickness>\n/gs;
  122.     
  123.     return $input;
  124. }
  125.  
  126. sub linescapital {
  127.     my($input, $size) = @_;
  128.  
  129.     $rest = $input;
  130.     while ($rest ne "") {
  131.         ($line, $rest) = ExtractOneLine($rest);
  132.         if (AllCaps($line)) {
  133.             $line = "<H$size>" . ConvertCase($line) . "</H$size>";
  134.         }
  135.         $output = $output . $line . "\r";
  136.     }
  137.     
  138.     return $output;
  139. }
  140.  
  141.  
  142. # Utilities
  143.  
  144. sub GetOneLine {
  145.     my($input) = @_;
  146.     
  147.     if ( $input =~ m/(.*?)[\r\n]/ ) {
  148.         return $1;
  149.     }
  150.     return $input;        # only one line long
  151. }
  152.  
  153. sub ExtractOneLine {
  154.     my($input) = @_;
  155.     
  156.     if ( $input =~ m/(.*?)\r/ ) {
  157.         return ($1, $');  #'
  158.     }
  159.     return $input;
  160. }
  161.  
  162. sub AllCaps {
  163.     my($input) = @_;
  164.     
  165.     if ( $input =~ m/(.*)[a-z](.*)/ ) {        # must contain no lower case letters
  166.         return 0;
  167.     }
  168.     if ( $input =~ m/(.*)[A-Z](.*)/ ) {        # must contain at least one letter
  169.         return 1;
  170.     }
  171.     return 0;
  172. }
  173.  
  174. sub ConvertCase {
  175.     my($input) = @_;
  176.     
  177.     $input =~ tr/A-Z/a-z/;
  178.     
  179.     return $input;
  180. }
  181.  
  182. sub Quote {
  183.     return "\"";
  184. }
  185.  
  186. 1;
  187.